<?
include "server_config.php";

$category_id = $_POST['c_id'];
$question_id = $_POST['q_id'];

if($category_id !="" && $question_id=="")
{
	$mode_category = true;
}
else
{
	$mode_category = false;


	$sql="
		SELECT category_id FROM nddg_question WHERE id = $question_id LIMIT 1 ;
	";

	$result = mysql_query($sql,$connect);
	$row = mysql_fetch_row($result);

	$category_id = $row[0];
}


if($mode_category)
{
	//새 질문 입력
	$sql="
		INSERT INTO nddg_question (category_id, content) VALUE ( $category_id, '$input_question');
	";

	$result = mysql_query($sql,$connect);	



	$sql="
		SELECT id FROM nddg_question WHERE category_id = $category_id AND content = '$input_question';
	";

	$result = mysql_query($sql,$connect);
	$row = mysql_fetch_row($result);

	$question_id = $row[0];

}

//답변 입력

if(trim($_POST['input_answer1'])!="")
{
	$sql="
		INSERT INTO nddg_answer (question_id, content) VALUE ( $question_id, '".trim($_POST['input_answer1'])."');
	";

	$result = mysql_query($sql,$connect);	
}
if(trim($_POST['input_answer2'])!="")
{
	$sql="
		INSERT INTO nddg_answer (question_id, content) VALUE ( $question_id, '".trim($_POST['input_answer2'])."');
	";

	$result = mysql_query($sql,$connect);	
}
if(trim($_POST['input_answer3'])!="")
{
	$sql="
		INSERT INTO nddg_answer (question_id, content) VALUE ( $question_id, '".trim($_POST['input_answer3'])."');
	";

	$result = mysql_query($sql,$connect);	
}

/*

$sql="
	SELECT name FROM nddg_question_category WHERE id = $category_id LIMIT 1 ;
";

$result = mysql_query($sql,$connect);
$row = mysql_fetch_row($result);

$category_name = $row[0];
*/
?>


<script>
location.href='nddg_db_category.php?question=<?=$question_id?>&r=<? echo rand(0,9999); ?>';
</script>